#pragma once

#ifndef __CR_IMAGE_LOADER_ERROR_H__
#define __CR_IMAGE_LOADER_ERROR_H__

NS_CR_BEGIN

namespace image
{
	namespace loader
	{
		enum class ErrorCode
		{
			OK = 0,
			CONNECTION_FAILURE,
			EMPTY_RESPONSE,
			HOST_RESOLUTION_FAILURE,
			INTERNAL_ERROR,
			INVALID_URL_FORMAT,
			NETWORK_RECEIVE_ERROR,
			NETWORK_SEND_FAILURE,
			OPERATION_TIMEDOUT,
			PROXY_RESOLUTION_FAILURE,
			SSL_CONNECT_ERROR,
			SSL_LOCAL_CERTIFICATE_ERROR,
			SSL_REMOTE_CERTIFICATE_ERROR,
			SSL_CACERT_ERROR,
			GENERIC_SSL_ERROR,
			UNSUPPORTED_PROTOCOL,
			UNKNOWN_ERROR = 1000,
			ERR_IMAGE_LOADER_BEGING = 2000,
			CANNOT_OPEN_OUT_FILE,
			ERR_IMAGE_LOADER_END,
		};

		class Error
		{
		public:
			Error()
				: code(ErrorCode::OK)
			{}
			template <typename TextType>
			Error(const int32_t& err_code, TextType&& p_error_message)
				: code{ (ErrorCode)err_code }
				, message{ _STD_FWD(p_error_message) }
			{}

			void operator=(const ErrorCode& err_code)
			{
				code = err_code;
			}
			
			explicit operator bool() const
			{
				return code != ErrorCode::OK;
			}

			ErrorCode code;
			string message;
		};
	}
}
NS_CR_END

#endif // !__CR_IMAGE_LOADER_ERROR_H__
